package com.qsmx.qingqiuticket.app.delegate.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.qsmx.qingqiuticket.app.R;
import com.qsmx.qingqiuticket.app.delegate.holder.PackageTicketListHolder;
import com.qsmx.qingqiuticket.app.entity.GroupPackageListEntity;
import com.qsmx.qingqiuticket.app.entity.PackageListEntity;

import java.util.List;

public class GroupPackageTicketListAdapter extends RecyclerView.Adapter<PackageTicketListHolder> {

    private Context mContext;
    private List<GroupPackageListEntity.BodyBean.ItemListBean> mData = null;

    public GroupPackageTicketListAdapter(Context mContext) {
        this.mContext = mContext;
    }

    public void setData(List<GroupPackageListEntity.BodyBean.ItemListBean> mData) {
        this.mData = mData;
    }

    @NonNull
    @Override
    public PackageTicketListHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new PackageTicketListHolder(LayoutInflater.from(mContext).inflate(R.layout.adapter_package_ticket_list, parent, false));
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void onBindViewHolder(@NonNull PackageTicketListHolder holder, int position) {
        if (mData.get(position).getType().equals("1")) {
            holder.tvTicketType.setText("门票");
            holder.tvTicketType.setTextColor(mContext.getColor(com.qsmx.core.R.color.font_red_color));
            holder.tvTicketType.setBackgroundResource(R.drawable.round_corner_white_bg_red_line);
        } else if (mData.get(position).getType().equals("3")) {
            holder.tvTicketType.setText("单项票");
            holder.tvTicketType.setTextColor(mContext.getColor(com.qsmx.core.R.color.orange));
            holder.tvTicketType.setBackgroundResource(R.drawable.round_corner_white_bg_orange_line);
        }
        holder.tvTicketName.setText(mData.get(position).getTradeName() + " " + mData.get(position).getQuantity() + "份");
    }

    @Override
    public int getItemCount() {
        if (mData == null) {
            return 0;
        } else {
            return mData.size();
        }
    }
}
